<template>
	<view class="app"> 
		<view class="navtop">
			<view class="order-nav" :style="{top:BarTop + 'px',height:BarHeight + 'px',lineHeight:BarHeight + 'px'}" v-if="!flexflag">
				<image src="https://yhflsyz.oss-cn-guangzhou.aliyuncs.com/img/back.png" mode="" class="order-nav-img" @click="backNav"></image>
				预约回收
			</view>
			<view class="order-nav navtwo" :style="{height:BarTop + BarHeight + 5 + 'px'}" v-else>
				<image :style="{top:BarTop + 'px',}" src="https://yhflsyz.oss-cn-guangzhou.aliyuncs.com/img/back.png" mode="" class="order-nav-img" @click="backNav"></image>
				<text :style="{top:BarTop + 'px',height:BarHeight + 'px',lineHeight:BarHeight + 'px'}" class="nav-sp">预约回收</text>
			</view>
		</view>
		<view >
			<view class="order-top" >
				<view class="order-menu-top">
					<view class="font-size: 36rpx;">欢迎参与</view>
					<view style="font-size: 48rpx;font-weight: bold;margin-top:10rpx;">绿色驿站智能回收</view>
				</view>
				<view class="order-menu">
					<view class="order-menu-main" style="height: 440rpx;" >
						<view class="order-menu-bigbox">
							<view  v-for="(item,index) in waste" :key="index" @click="getcategory(index,item)" :class="[styleishidden == index ? 'activeClass' : '', 'order-menu-box']">
								<image :src=" url + item.image" mode="" style="width: 100rpx;height: 100rpx; margin-left: 20rpx;"></image>
								<text style="width: 140rpx;font-size: 24rpx;text-align: center;display: inline-block; color: #66656A;font-weight: bold;">{{item.name}}</text>
								<image src="https://yhflsyz.oss-cn-guangzhou.aliyuncs.com/img/selected.png" mode="" class="selected" :style="{ 'display': styleishidden === index ? 'block' : 'none' }"></image>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="box-card order-info">
				<view class="box-card-top">
					<view class="box-card-left"></view>
					<text class="box-card-center">回收信息</text>
				</view>
				<u-form :model="order" ref="uForm" >
					<u-form-item prop="orderAddressId" label="回收地址" :label-align="labelAlign" :label-width="labelWidth">
						<image src="https://yhflsyz.oss-cn-guangzhou.aliyuncs.com/img/Subtractimg.png" mode="" style="width: 24rpx;height: 29rpx;left: 20rpx;" class="leftform"></image>
						<view class="address-goto-choose" @click="chooseAddress">
							<text class="address-goto-choose-tips">{{ addressShow }}</text>
							<u-icon name="arrow-right" color="#888"></u-icon>
						</view> 
					</u-form-item>
					<u-form-item prop="orderBookType" label="上门时间" :label-align="labelAlign" :label-width="labelWidth">
						<image src="https://yhflsyz.oss-cn-guangzhou.aliyuncs.com/img/f330527455352735cb8e81402b9d0c2.png" mode="" class="leftform"></image>
						<view class="address-goto-choose" @click="showOrderBookType=true">
							<!-- <text>{{ orderBookType[order.orderBookType].label }}</text> -->
							<text class="address-goto-choose-tips">{{bookDateTime}}</text>
							<u-icon name="arrow-right" color="#888"></u-icon>
						</view>  
						<!-- <u-select v-model="showOrderBookType" :list="orderBookType"  @confirm="orderBookTypeConfirm"></u-select> -->
						<u-popup v-model="showOrderBookType" border-radius="20" mode="bottom">
							<view class="date-popup">
								<view class="date-choose">
									<view class="date-title">选择上门日期</view>
									<scroll-view class="date-box" scroll-x>
										<view class="date-item" v-for="(item,index) in bookDateArr" :key="index" :class="bookDateIndex==index?'choose':''" @click="chooseDate(index)">
											<view class="date-items">
												<view>{{item.date}}</view>
												<view class="mt-20">{{item.week}}</view>
											</view>
										</view>		
									</scroll-view>
								</view>
								<view class="time-choose">
									<view class="time-title">选择上门时间</view>
									<view class="time-box">
										<block v-for="(item,index) in bookTimeArr" :key="index">
											<view class="time-item" v-if="!item.disabled" :class="bookTimeIndex==index?'choose':''" @click="chooseTime(index)">{{item.time}}</view>
											<view class="time-item disabled" v-else>{{item.time}}</view>
										</block>
									</view>
								</view>
								<view class="choose-date-btn" @click="confirmBookDate">确定</view>
							</view>
						</u-popup>
					</u-form-item>
					<u-form-item v-show="order.orderBookType == 1" prop="orderBookTime" label="指定时间" :label-align="labelAlign" :label-width="labelWidth">
						<image src="https://yhflsyz.oss-cn-guangzhou.aliyuncs.com/img/f330527455352735cb8e81402b9d0c2.png" mode="" class="leftform"></image>
						<view class="address-goto-choose" @click="showOrderBookTime=true">
							<text>{{ defaultOrderBookTime  }}</text>
							<u-icon name="arrow-right"></u-icon>
						</view>  
						<u-picker :default-time="defaultOrderBookTime" @confirm="orderBookTimeConfirm" mode="time" v-model="showOrderBookTime" :params="orderBookTimeParams"></u-picker>
					</u-form-item>
				</u-form> 
				
				<view class="box-card-top1">
					<view class="box-card-left1"></view>
					<text class="box-card-center1">预估重量</text>
					<view class="box-card-right-yu" >
						2公斤起收
					</view>
				</view>
				<view class="box-card-box">
					<u-slider v-model="order.orderWeight" min="2" max="100" height='20'></u-slider>
					<view class="weightbox">
						<view class="weightsp">
							预估重量(公斤):
						</view>
						<input type="text" v-model="order.orderWeight" class="weightipt" disabled="disabled"/>
					</view>
				</view>
			</view>
			<view>
				<view class="waste-content box-card">
					<view class="waste-estimate-title" style="padding-bottom: 20rpx;">
						<view class="waste-estimate-title-left">请将回收物品拍照上传：</view>
					</view>
					<view class="waste-content-input">
						<u-upload ref="uUpload"  width="160rpx" height="160rpx" max-count="5" :action="uploadUrl" :header="uploadHeader" :file-list="fileList" ></u-upload>
					</view>
				</view>
				<view class="waste-content box-card">
					<view class="waste-estimate-title" style="padding-bottom: 10rpx;">
						<view class="waste-estimate-title-left">订单备注：</view>
					</view>
					<view class="waste-content-input">
						<u-input placeholder="请输入备注信息"  maxlength="200" v-model="order.remarks" type="textarea"  :auto-height="true" />
					</view>
				</view>
				<view class="hidden"></view>
				<view class="order-bottom-row">
					<view class="order-bottom-row-money">
						<text class="order-bottom-row-sp">预估价:</text> 
						<text class="order-bottom-row-pc">￥{{estimateMoney}}</text>
					</view>
					<view class="order-bottom-row-sm">
						成交价根据实际重量为准
					</view>
					<view class="order-bottom-row-btn" @click="submitOrder">
						提交
					</view>
				</view>
				<c-safe-bottom></c-safe-bottom>
			</view> 
		</view>		
		<view>
			<view class="popup-cover" v-if="popupVisibleC"></view>
			<view class="bottom-popup-mask" v-if="popupVisibleC">
			    <view class="bottom-popup-content">
					<view class="popup-box">
						<image src="https://yhflsyz.oss-cn-guangzhou.aliyuncs.com/img/Group 2110@2x.png" mode="" style="width: 100%;height: 100%;"></image>
						<text class="popup-title">预约成功</text>
						<text class="popup-content">回收员{{defaultOrderBookTime?'接单后将尽快上门':'接单后将在约定时间上门'}},请保持通讯畅通</text>
						<view class="popop-btn-box">
							<view class="popop-btn" @click="GotoIndex">
								知道了
							</view>
						</view>
					</view>
			    </view>
			</view>
		</view>
		
	</view>
</template>
<style scoped> 
	/deep/ .u-form-item {padding: 20rpx !important;white-space: nowrap;}
	/deep/ .u-form-item--left {}
	/deep/ .u-flex {overflow: hidden !important;}
	/deep/ .u-flex view {overflow: hidden !important;}
	.address-goto-choose {overflow: hidden;display: flex;align-items: center;justify-content: space-between; margin-left: 20rpx;}
	.address-goto-choose-tips {overflow: hidden;flex: 1;color: #888;font-size: 28rpx;text-overflow: ellipsis;}
	.site-info{overflow: hidden;} 
	.waste-checkbox-group{ display: flex;width:100%;flex-direction: column;}
	.category-panel{width: 100%;}
	.waste-item{ padding:20rpx;border-top: 1rpx solid #eee;display: flex;align-items: center;justify-content: space-between;}
	.waste-estimate{ }
	.waste-estimate .waste-item{ padding:10rpx 20rpx;}
	.waste-estimate-title-right{font-size: 22rpx;color:#aaa;font-weight: normal;margin-left: 30rpx;margin-top: 10rpx;}
	.waste-estimate-right{flex:1;display: flex;align-items: center;margin-left: 20rpx;justify-content: flex-end;}
	.waste-estimate-input{margin:0 10rpx;}
	.waste-estimate-sum{ display: flex;align-items: center;padding:20rpx;border-top: 1rpx solid #eee;}
	.waste-estimate-money{flex:1;text-align: right;}
	.waste-estimate-money-text{font-weight: bold;color:red;margin:0 10rpx;}
	.order-bottom-row {width: 100%;height: 136rpx;position: fixed;bottom: 0;background-color: white;z-index: 10;}
	.order-top{width: 100%; margin-top: -530rpx;}
	/* .order-nav{width: 100%;font-size: 32rpx;font-weight: bold;text-align: center;position: absolute;top:0;color: black; } */
	/* .order-nav-img{width: 40rpx;height: 40rpx;position: absolute;left: 0rpx;padding: 10rpx 15rpx 15rpx 15rpx;} */
	.order-menu-top{color: black; margin: 10rpx 26rpx 24rpx 26rpx;}
	.order-menu{box-sizing: border-box; margin: 20rpx 26rpx 24rpx 26rpx;}
	.order-menu-main{padding: 20px;background-color: white;border-radius: 15rpx;}
	.order-menu-bigbox{width: 100%;height:350rpx;display: flex;flex-wrap: wrap; justify-content: space-between;align-items: center;}
	.order-menu-box{width: 140rpx;height: 160rpx;border: 1px  rgba(17,207,102,0.4) solid;position: relative; border-radius: 18rpx;}
	.activeClass{border: 1px solid #11CF66; }
	.selected{width: 30rpx;height: 30rpx;position: absolute;right: 0;bottom: 0;}
	.order-menu-selected{width: 100%;height: 96rpx; background-color: #fbfafafd;margin-top: 30rpx;border-radius: 16rpx;position: relative;}
	.right{position: absolute;right: 50rpx;top: 30rpx;font-size: 27rpx;font-weight: bold;color: black;}
	.right-img{width: 14rpx;height:26rpx;position: absolute;top: 35rpx;right: 20rpx;}
	.off{width: 50rpx;height: 50rpx;position: absolute;top: 20rpx;right: 5%;}
	.title{position: absolute;top: 25rpx;left: 5%;font-size: 32rpx;color: black;font-weight: bold;}
	.pllist{position: absolute;width: 90%;height: 300rpx;left: 5%;margin-top: 40rpx;display: flex;justify-content: space-between;flex-wrap: wrap;}
	.list{position: relative; width: 216rpx;height: 84rpx;background-color: rgba(246, 246, 246, 1);border-radius: 16rpx;font-size: 25rpx;line-height: 84rpx;text-align: center;color: black;}
	.listbutton{width: 90%;background-color: rgba(54, 190, 106, 1);color: white;font-size: 24rpx; height: 88rpx;line-height: 88rpx;text-align: center;position: absolute;bottom: 20rpx;left: 5%;border-radius: 16rpx;}
	.box-card-top{ font-size: 32rpx;font-weight: bold;color: black;position: relative;top: 20rpx;margin-bottom: 20rpx;height: 40rpx;}
	.box-card-top1{
		margin-top: 30rpx;
		height: 44rpx;
		width: 100%;
		display: flex;
	}
	.box-card-left1{
		width: 12rpx;height: 40rpx;background-color: #11CF66;border-radius: 10px;
	}
	.box-card-center1{
		font-size: 32rpx;
		width: 488rpx;
		color: #333333;
		font-weight: bold;
		margin-left: 20rpx;
	}
	.box-card-box{
		width: 630rpx;
		margin: 30rpx;
		margin-top: 50rpx;
	}
	.weightbox{
		width: 500rpx;
		margin-left:65rpx;
		height: 50rpx;
		margin-top: 30rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.weightsp{
		font-size: 28rpx;
		height: 50rpx;
		line-height: 50rpx;
	}
	.weightipt{
		display: block;
		border: none;
		width: 80rpx;
	}

	.box-card-left{width: 12rpx;height: 40rpx;background-color: #11CF66;border-radius: 10px;position: absolute;left: 0;top: 0;}
	.box-card-center{position: absolute;left: 50rpx;top: 0;}
	.box-card-right{ font-size:24rpx;color: rgba(54, 190, 106, 1);position: absolute;left: 180rpx;padding-right: 7rpx; border: 1px rgba(54, 190, 106, 1) solid;height: 39rpx;width: 260rpx;text-align: right;line-height: 39rpx;border-radius: 16rpx;}
	.box-card-right-yu{font-size:24rpx;color: #36BE6A;padding-right: 7rpx;background-color: #d4fbe3; height: 44rpx;width: 152rpx;text-align: center;line-height: 44rpx;border-radius: 8rpx;}
	.box-card-sp{ margin: -1rpx; background-color: rgba(54, 190, 106, 1);color: white;position: absolute;left: 0;border-radius: 16rpx;width: 82rpx;text-align: center;}
	.leftform{width: 33rpx;height: 33rpx;position: absolute;left: 15rpx;top: 40rpx;}
	.hidden{width: 100%;height: 130rpx;}
	.order-bottom-row-btn{ width: 342rpx;height: 90rpx;border-radius: 49rpx;text-align: center;line-height: 90rpx; color: white;background-color:rgba(54, 190, 106, 1) ;position: absolute;right: 30rpx;top: 24rpx;}
	.order-bottom-row-sp{position: absolute;left: 50rpx;font-size: 28rpx;color: rgba(0, 0, 0, 1);top: 32rpx;}
	.order-bottom-row-pc{position: absolute;left: 160rpx;font-size: 28rpx;color: rgba(244, 95, 84, 1);top: 32rpx;}
	.order-bottom-row-sm{position: absolute;left: 50rpx;font-size: 28rpx;color: rgba(153, 153, 153, 1);top: 70rpx;}
	
	.date-popup{margin: 30rpx;}
	.date-title,.time-title{font-size: 28rpx; font-weight: bold;}
	.date-box{width: 100%; margin-top: 20rpx;}
	.date-item{height: 130rpx; width: 130rpx; margin-right: 20rpx; border-radius: 10rpx; display: inline-block; background: #f7f7f7;color:#333;}
	.date-item:last-of-type{margin-right: 0;}
	.date-items{display: flex;flex-direction: column; align-items: center;justify-content: center;width: 100%; height: 100%;}
	.time-box{display: flex; flex-wrap: wrap; box-sizing: border-box; margin-top: 20rpx;}
	.time-item{width: 335rpx; height:90rpx; line-height:90rpx; box-sizing: border-box; text-align: center; border-radius: 10rpx; background: #f7f7f7;color:#333; margin-bottom: 20rpx; margin-right: 20rpx;}
	.time-item:nth-of-type(even){margin-right: 0;}
	.disabled{background: #F8F8F8;color: #D2D2D2;}
	.choose{color: #fff; background-color:rgba(54, 190, 106, 1);}
	.choose-date-btn{ width: 690rpx;height: 90rpx; line-height:90rpx;border-radius: 49rpx;text-align: center; margin-top:30rpx; color: white;background-color:rgba(54, 190, 106, 1) ;}
    .mt-20{margin-top: -20rpx;}
	
	.navtop{ width: 100%;height: 694rpx;background: url('https://yhflsyz.oss-cn-guangzhou.aliyuncs.com/img/Maskgroup.png') center/cover;z-index: -1;}
	.order-nav{width: 100%;font-size: 32rpx;font-weight: bold;text-align: center;position: fixed;color: black;z-index: 999;}
	.navtwo{background-color: white;}
	.order-nav-img{width: 40rpx;height: 40rpx;position: absolute;left: 0rpx;padding: 10rpx 15rpx 15rpx 10rpx;z-index: 999;}
	.nav-sp{position: absolute;width: 100%;left: 0rpx;text-align: center;}
</style>
<script>
	export default {
		data() {
			return {
				flexflag:false,
				labelWidth: 150,
				labelAlign: "right", 
				styleishidden:0,
				pllist:[],
				count:1,
				url:'https://admin.cqycgyl.com',
				popupVisible: false, // 控制弹出层显隐的变量
				popupVisibleC:false,
				order:{
					orderBookType:0,
					orderNote:"",
					orderWeight:10,
					estimate_price:0
				},
				BarTop:'',
				BarHeight:'',
				flagUp:false,
				site:{},
				waste:[],
				rules:[],
				Pllistys:[],
				categoryIndex:0,
				wasteCheckList:[],
				uploadUrl:this.$u.api.user.getUploadUrl(),
				uploadHeader:this.$u.api.user.getUploadHeader(),
				fileList:[],
				showOrderBookType:false,
				orderBookType:[
					{value: '0',label: '尽快'},
					{value: '1',label: '指定时间'}
				],
				showOrderBookTime:false,
				orderBookTimeParams:{ 
					year: false,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: false,
					// 选择时间的时间戳
					timestamp: true,
				},
				defaultOrderBookTime:"",
				bookDateIndex: 0,
				bookTimeIndex: 0,
				bookDate: '',
				bookTime: '',
				bookDateArr: [],
				bookTimeArr: [],
				bookTimeArrToday: [
					{
						time: '最近两小时',
						index: 0,
						disabled: false,
					},
					{
						time: '9:00-11:00',
						index: 1,
						disabled: false,
					},
					{
						time: '11:00-13:00',
						index: 2,
						disabled: false,
					},
					{
						time: '13:00-15:00',
						index: 3,
						disabled: false,
					},
					{
						time: '15:00-17:00',
						index: 4,
						disabled: false,
					},
					{
						time: '17:00-19:00',
						index: 5,
						disabled: false,
					}
				],
				bookTimeArrOther: [
					{
						time: '9:00-11:00',
						index: 0,
						disabled: false,
					},
					{
						time: '11:00-13:00',
						index: 1,
						disabled: false,
					},
					{
						time: '13:00-15:00',
						index: 2,
						disabled: false,
					},
					{
						time: '15:00-17:00',
						index: 3,
						disabled: false,
					},
					{
						time: '17:00-19:00',
						index: 4,
						disabled: false,
					}
				],
				bookDateTime: '最近两小时'
			}
		}, 
		computed:{
			isItemSelected() {
			    return (itemId) => {
			      // 使用find方法查找selectedItems中是否有匹配的wasteId
			      return this.Pllistys.find(item => item.wasteId === itemId) !== undefined;
			    };
			},
			addressShow(){
				this.order.orderAddressInfo = this.vuex_chooseAddress || {} 
				if(!this.order?.orderAddressInfo?.addressId){
					this.getDefaultAddress()
					return "请选择回收地址"
				}
				this.order.address_id = this.order?.orderAddressInfo?.addressId || 0
				return `${this.order.orderAddressInfo.addressContacts}，${this.order.orderAddressInfo.addressName}`
			},
			estimateMoney(){
				let sum = 0
				this.waste.forEach((item,index) =>{
					if(this.styleishidden == index){
						sum = (this.order.orderWeight-0)*item.avarage_price
					}
				})
				this.order.estimate_price = sum.toFixed(2)
				return sum.toFixed(2)
			}
		},
		onPageScroll(e) {
			if (e.scrollTop > 50) {
				this.flexflag = true
			} else {
			  this.flexflag = false
			}
		},
		methods:{
			weight(index,item){
				this.count = index
				this.order.orderWeight = item
			},
			GotoIndex(){
				this.popupVisibleC = false;
				uni.switchTab({
					url:'/pages/index/index'
				})
			},
			updatePopupVisible(visible) {
			  this.popupVisible = visible;
			},
			getcategory(index,item){
				this.order.book_category=item.name;
				this.styleishidden = index
			},
			getDefaultAddress(){
				this.$u.api.address.getAddressList({
					addressDefault:1
				}).then(res => { 
					if(res?.status != 200 || !res?.data?.list?.length ){
						return false
					}
					this.$u.vuex('vuex_chooseAddress',res?.data?.list?.[0] || {}) 
				})
			},
			gotoPage(path){
				uni.navigateTo({ url: path });
			},
			chooseAddress(){
				this.gotoPage("/pageA/address/index?choose=1")
			},
			getSiteWaste(){
				this.$u.api.index.getWasteList().then(res => {
					this.waste = res.data || []
					this.waste.forEach((el,index) =>{
						if(el.name == this.name){
							this.styleishidden = index
							this.order.book_category=el.name;
						}
					})
					let arr = res.data.filter(val => {
						if(val.waste.length >0){
							return val.waste
						}
						
					})
					if(this.order?.orderBookInfo){
						this.waste.forEach((category,categoryIndex) => {
							category.waste.forEach((waste,wasteIndex) => {
								this.order?.orderBookInfo.forEach(orderWaste => {
									if(waste.wasteId == orderWaste.wasteId){ 
										this.$set(category.waste,wasteIndex,orderWaste)
										this.wasteCheckList.push(orderWaste.wasteId)
									}
								})
							}) 
							this.$set(this.waste,categoryIndex,category)
						}) 
					}
				})
			},
			categoryChange(index){
				this.categoryIndex = index
			},
			categorySwiperChange(e){
				this.categoryIndex = e.detail.current
			},
			wasteCheckboxChange(e){
				this.wasteCheckList = e 
			},
			orderBookTypeConfirm(e){
				this.order.orderBookType = e[0].value 
				if(this.order.orderBookType == 1){
					this.order.book_time = (Date.now()  / 1000 + 3600).toFixed(0)
					this.defaultOrderBookTime = this.$u.timeFormat(this.order.book_time  * 1000 , 'yyyy-mm-dd hh:MM');
				}
			},
			orderBookTimeConfirm(e){
				this.order.book_time = e.timestamp
				this.defaultOrderBookTime = this.$u.timeFormat(this.order.book_time * 1000, 'yyyy-mm-dd hh:MM');
			},
			submitOrder(){
				let files = []
				let hasUpload = false
				this.$refs.uUpload.lists.forEach(item => {
					if(item.progress < 100){
						hasUpload = true
						return true
					}
					if(item?.response == undefined && item?.url){
						files.push(item.url) 
						return true
					}
						 
					if((item?.response?.status != 200 || item?.response?.data == undefined || item?.response?.data == '')){
						return true
					}
					files.push(item.response.data) 
				})  
				if(!this.order?.orderAddressInfo?.addressId){
					this.$u.toast('请选择回收地址')
					return false
				}
				if(hasUpload){
					this.$u.toast('有图片正在上传，请耐心等待')
					return false
				}
				this.order.book_photo = files 
				// this.order.book_time = this.defaultOrderBookTime
				this.order.book_time = this.bookDateTime
				if(!this.flagUp){
					this.$u.api.order.saveOrder(this.order).then(res => {
						if(res.code != 1){ 
							return false
						}
						uni.$emit('orderListUpdate')
						uni.$emit('orderInfoUpdate')
						
						this.popupVisibleC = true;
					}).catch(err => {
						this.$u.toast('保存失败')
					})
				}else{
					let obj ={
						order_id:this.order.id,
						...this.order
					}
					this.$u.api.order.editOrder(obj).then(res =>{
						if(res.code == 1){
							uni.showToast({
								title: '修改成功',
								icon: 'success',
								duration: 1500
							}) 
							setTimeout(()=>{
								uni.navigateBack({delta:1,})
							},1500)
						} else{
							uni.showToast({
								title: res.msg,
								icon: 'error',
								duration: 1500
							}) 
							setTimeout(()=>{
								uni.navigateBack({delta:1,})
							},1500)
						}
					}).catch(req =>{
						uni.showToast({
							title: req.msg,
							icon: 'error',
							duration: 1500
						}) 
						setTimeout(()=>{
							uni.navigateBack({delta:1,})
						},1500)
					})
				}
			},
			getOrderInfo(orderId){
				this.$u.api.order.getOrderInfo({id:orderId}).then(res => {
					if(res.code != 1){ 
						return false
					}
					this.order = res.data
					if(this.order.status == -1 || this.order.status == 2){
						uni.$emit('orderListUpdate')
						uni.$emit('orderInfoUpdate')
						uni.navigateBack();
						return false
					}
					this.defaultOrderBookTime = this.order.orderBookTime
					if(this.order?.book_photo){
						this.order?.book_photo.forEach(item => {
							this.fileList.push({url:item})
						})
					}
				})
			},
			backNav(){
				uni.navigateBack({
					delta:1,
				})
			},
			chooseDate(index){
				if(this.bookDateIndex==index){
					return
				}
				this.bookDateIndex = index
				if(index == 0){
					this.bookTimeArr = this.bookTimeArrToday
				}else{
					this.bookTimeArr = this.bookTimeArrOther
				}
				this.bookTimeIndex = 0
			},
			chooseTime(index){
		        if(this.bookTimeArr[index].disabled){
					return
				}
				if(this.bookTimeIndex==index){
					return
				}
				this.bookTimeIndex = index
			},
			confirmBookDate(){
				if(this.bookTimeArr[this.bookTimeIndex].disabled){
					this.$u.toast('请选择上门时间')
					return
				}
				if(this.bookDateIndex==0 && this.bookTimeIndex==0){
					this.bookDateTime = '最近两小时'
				}else{
					this.bookDateTime = this.bookDateArr[this.bookDateIndex].date + ' ' + this.bookTimeArr[this.bookTimeIndex].time
				}
				this.showOrderBookType = false
			},
			getLastSevenDays(){
				let dates = [];
				let today = new Date();
				for (let i = 0; i < 7; i++) {
					let date = new Date(today);
					date.setDate(today.getDate() + i);
					let newdate = date.toISOString('MM-dd').split('T')[0].substr(5);
					
					let week;
					if(i==0){
						week = '今天'
					}else{
						let weeknum = date.getDay();
						switch (weeknum){
							case 0:
							    week = '星期日'
								break;
							case 1:
							    week = '星期一'
								break;
							case 2:
							    week = '星期二'
								break;
							case 3:
							    week = '星期三'
								break;
							case 4:
							    week = '星期四'
								break;
							case 5:
							    week = '星期五'
								break;
							case 6:
							    week = '星期六'
								break;
							default:
								break;
						}
					}
					dates.push({ week: week, date: newdate, index:i });
				}
				return dates;
			},	
		},
		onLoad(option){
			this.defaultOrderBookTime = this.$u.timeFormat(Date.now() + 3600 * 1000, 'yyyy-mm-dd hh:MM');
			if(option?.orderId){
				this.flagUp = true
				this.getOrderInfo(option.orderId)
			} 
			this.name = option.name
			let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
			   this.BarTop = menuButtonInfo.top;
			   this.BarHeight = menuButtonInfo.height;
			   this.getSiteWaste()
		}, 
		onShow() {
			let now = new Date();
			let hour = now.getHours();
			
			if(hour >= 19){
				this.bookDateIndex = 1
				this.bookTimeArr = this.bookTimeArrOther
				
				this.bookTimeArrToday.map(item=>{
					item.disabled = true
				})
			}else{
				this.bookTimeArr = this.bookTimeArrToday
				
				this.bookTimeArr.map(item=>{
					if(hour>=item.time.split(':')[0]){
						item.disabled = true
					}
				})
			}
		},
		// 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
		onReady() {
			this.$refs.uForm.setRules(this.rules);  
			
			this.bookDateArr = this.getLastSevenDays();
			let now = new Date();
			let hour = now.getHours();
			
			if(hour >= 19){
				this.bookDateIndex = 1
				this.bookTimeArr = this.bookTimeArrOther
				
				this.bookTimeArrToday.map(item=>{
					item.disabled = true
				})
				
				this.bookDateTime = this.bookDateArr[this.bookDateIndex].date + ' ' + this.bookTimeArr[this.bookTimeIndex].time
			}else{
				this.bookTimeArr = this.bookTimeArrToday
				this.bookTimeArr.map(item=>{
					if(hour>=item.time.split(':')[0]){
						item.disabled = true
					}
				})
			}
		} 
	}
</script>